const fs = require('fs')
const path = require('path')
const chalk = require('chalk')
const { runCommand } = require('./runCommand')
/**
 * 构建uni项目
 * @param {*} projectPath 项目存放目录
 * @returns buildedPath 构建完后小程序项目实际目录
 */
module.exports = (projectPath) => {
  // 检测是否为uni项目
  let isUniApp = fs.existsSync(`${projectPath}/index.html`)
  let buildedPath = ''
  if (isUniApp) {
    console.log(chalk.blue('\n开始构建uni小程序--------------->'))
    runCommand(`sh ${path.join(__dirname, '../shell/uniConstruct.sh')} ${projectPath}`)
    buildedPath = `${projectPath}/dist/build/mp-weixin`
    console.log(chalk.blue('构建完成uni小程序--------------->\n'))
  } else {
    buildedPath = projectPath
  }
  return buildedPath
}